#ifndef __GAME_SORT_H__
#define __GAME_SORT_H__
#include "game_platform.h"
#include "game.h"
struct sort_entry {
    real32 SortKey;
    uint32 Index;
};

inline sort_sprite_bound *GetSortEntries(game_render_commands *Commands) {
    sort_sprite_bound *SortEntries = (sort_sprite_bound *)(Commands->PushBufferBase);
    return SortEntries;
}

struct sprite_graph_walk {
    sort_sprite_bound *InputNodes;
    uint32 *OutIndex;
    bool32 HitCycle;
};

#define SORT_GRID_WIDTH 16
#define SORT_GRID_HEIGHT 9
struct sort_grid_entry {
    sort_grid_entry *Next;
    uint32 OccupantIndex;
};

void MergeSort(uint32 Count, sort_entry *First, sort_entry *Temp);
void BubbleSort(uint32 Count, sort_entry *First, sort_entry *Temp);
void RadixSort(uint32 Count, sort_entry *First, sort_entry *Temp);
void MergeSort(uint32 Count, sort_sprite_bound *First, sort_sprite_bound *Temp);
void SeparatedMergeSort(uint32 Count, sort_sprite_bound *First, sort_sprite_bound *Temp);
void RecursiveFontToBack(sprite_graph_walk *Walks, uint32 AtIndex);
void WalkSpriteGraph(uint32 InputNodeCount, sort_sprite_bound *InputNodes, uint32 *OutIndexArray);
uint32 BuildSpriteGraph(uint32 InputNodeCount, sort_sprite_bound *InputNodes, memory_arena *Arena,
                        uint32 ScreenWidth, uint32 ScreenHeight);
bool32 IsZSprite(sprite_bound Bound);
uint32 *SortEntries(game_render_commands *Commands, memory_arena *TempArena,
                    game_render_prep *Prep);
#endif